<template>
	<el-container>
		<el-header>
			<div class="left-panel">
			</div>
            <div class="right-panel">
                <div class="right-panel-search">
                    <el-select v-model="status" placeholder="状态" clearable>
                        <el-option label="未读" :value="0"></el-option>
                        <el-option label="已读" :value="1"></el-option>
                        <el-option label="全部" :value="-1"></el-option>
                    </el-select>
                    <el-date-picker v-model="search.date" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
                </div>
            </div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" stripe :params="{status: status}" border>
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="消息内容" prop="appId" width="600">
                    <template #default="{row}">
                        <div style="display: flex;">
                            <el-link type="primary" style="width: 230px;justify-content: flex-start;" @click="table_show(row)" :underline="false">{{ row.order_no }}</el-link>
			                <el-button size="small" @click="table_jump(row)" >跳转列表</el-button>
			                <el-button size="small" @click="table_read(row)">强制已读</el-button>
                        </div>
					</template>
                </el-table-column>
				<el-table-column label="备注" prop="remark"></el-table-column>
				<el-table-column label="供应商" prop="apply.apply_name"></el-table-column>
				<el-table-column label="消息类型" prop="from_type">
                    <template #default="{row}">
                        {{row.from_type}}
                        {{row.from_type == 1 ? '采购单' : row.from_type == 2 ? '采购入库单' : row.from_type == 3 ? '染色单' : row.from_type == 4 ? '加工单' : row.from_type == 5 ? '检验单' : row.from_type == 6 ? '调拨单' : row.from_type == 7 ? '发货单' : row.from_type == 8 ? '销售单' : row.from_type == 9 ? '染色入库单' : '加工入库单'}}
					</template>
                </el-table-column>
				<el-table-column label="接收员" prop="receive_name" align="center"></el-table-column>
				<el-table-column label="状态" prop="status">
                    <template #default="{row}">
                        <el-tag :type="row.status == 0 ? 'danger' : 'success'">{{row.status == 0 ? '未读' : '已读'}}</el-tag>
					</template>
                </el-table-column>
				<el-table-column label="创建时间" prop="create_time"></el-table-column>
			</scTable>
		</el-main>
	</el-container>
    <purchase-dialog v-if="dialog.purchase" ref="purchaseDialog" @success="handleSuccess" @closed="dialog.purchase = false"></purchase-dialog>
    <house-dialog v-if="dialog.house" ref="houseDialog" @success="handleSuccess" @closed="dialog.house = false"></house-dialog>

    <dye-dialog v-if="dialog.dye" ref="dyeDialog" @success="handleSuccess" @closed="dialog.dye = false"></dye-dialog>
    <dyehouse-dialog v-if="dialog.dyehouse" ref="dyehouseDialog" @success="handleSuccess" @closed="dialog.dye = false"></dyehouse-dialog>

    <machine-dialog v-if="dialog.machine" ref="machineDialog" @success="handleSuccess" @closed="dialog.machine = false"></machine-dialog>
    <machinehouse-dialog v-if="dialog.machinehouse" ref="machinehouseDialog" @success="handleSuccess" @closed="dialog.machine = false"></machinehouse-dialog>

    <test-dialog v-if="dialog.test" ref="testDialog" @success="handleSuccess" @closed="dialog.test = false"></test-dialog>
    <diaobo-dialog v-if="dialog.diaobo" ref="diaoboDialog" @success="handleSuccess" @closed="dialog.diaobo = false"></diaobo-dialog>
    <send-dialog v-if="dialog.send" ref="sendDialog" @success="handleSuccess" @closed="dialog.send = false"></send-dialog>
    <sale-dialog v-if="dialog.sale" ref="saleDialog" @success="handleSuccess" @closed="dialog.sale = false"></sale-dialog>
</template>

<script>
import purchaseDialog from '@/views/business/purchase/purchase/save.vue'
import houseDialog from '@/views/business/purchase/arrival/save.vue'

import dyeDialog from '@/views/business/dye/order/save.vue'
import dyehouseDialog from '@/views/business/dye/house/save.vue'

import machineDialog from '@/views/business/machining/order/save.vue'
import machinehouseDialog from '@/views/business/machining/house/save.vue'

import testDialog from '@/views/business/inspect/order/save.vue'
import diaoboDialog from '@/views/business/purchase/allot/save.vue'
import sendDialog from '@/views/business/ware/send/save.vue'
import saleDialog from '@/views/business/sale/order/save.vue'
export default {
	name: "client",
    components: {
        purchaseDialog, houseDialog, dyeDialog, dyehouseDialog, machineDialog, machinehouseDialog, testDialog, diaoboDialog, sendDialog, saleDialog
    },
	data() {
		return {
			apiObj: this.$API.tips.list,
			selection: [],
            search: {
                status: null
            },
            dialog: {
                purchase: false,
                house: false,
                dye: false,
                dyehouse: false,
                machine: false,
                machinehouse: false,
                test: false,
                diaobo: false,
            },
            status: 0,
		}
	},
	methods: {
        // 跳转
        table_jump(row){
            if(row.from_type == 1){
                this.$router.push({
                    path: '/business/purchase/purchase',
                    query: {code: row.order_no},
                });
            }else if(row.from_type == 2){
                this.$router.push({
                    path: '/business/purchase/arrival',
                    query: {code: row.order_no},
                });
            }else if(row.from_type == 3){
                this.$router.push({
                    path: '/business/dye/order',
                    query: {code: row.order_no},
                });
            }else if(row.from_type == 4){
                this.$router.push({
                    path: '/business/machining/order',
                    query: {code: row.order_no},
                });
            }else if(row.from_type == 5){
                this.$router.push({
                    path: '/business/inspect/order',
                    query: {code: row.order_no},
                });
            }else if(row.from_type == 6){
                this.$router.push({
                    path: '/business/purchase/allot',
                    query: {code: row.order_no},
                });
            }else if(row.from_type == 7){
                this.$router.push({
                    path: '/business/ware/send',
                    query: {code: row.order_no},
                });
            }else if(row.from_type == 8){
                this.$router.push({
                    path: '/business/sale/order',
                    query: {code: row.order_no},
                });
            }else if(row.from_type == 9){
                this.$router.push({
                    path: '/business/dye/house',
                    query: {code: row.order_no},
                });
            }else if(row.from_type == 10){
                this.$router.push({
                    path: '/business/machining/house',
                    query: {code: row.order_no},
                });
            }
        },
		//查看
		table_show(row) {
            let query = {}
			if(row.from_type == 1){
                query = {
                    id: row.value_id,
                    purchase_code: row.order_no
                }
                this.dialog.purchase = true
                this.$nextTick(() => {
                    this.$refs.purchaseDialog.open('show').setData(query)
                })
            }else if(row.from_type == 2){
                query = {
                    id: row.value_id,
                    purchase_ware_code: row.order_no
                }
                this.dialog.house = true
                this.$nextTick(() => {
                    this.$refs.houseDialog.open('show').setData(query)
                })
            }else if(row.from_type == 3){
                query = {
                    id: row.value_id,
                    purchase_dye_code: row.order_no
                }
                this.dialog.dye = true
                this.$nextTick(() => {
                    this.$refs.dyeDialog.open('show').setData(query)
                })
            }else if(row.from_type == 9){
                query = {
                    id: row.value_id,
                    purchase_dye_code: row.order_no
                }
                this.dialog.dyehouse = true
                this.$nextTick(() => {
                    this.$refs.dyehouseDialog.open('show').setData(query)
                })
            }else if(row.from_type == 10){
                query = {
                    id: row.value_id,
                    purchase_dye_code: row.order_no
                }
                this.dialog.machinehouse = true
                this.$nextTick(() => {
                    this.$refs.machinehouseDialog.open('show').setData(query)
                })
            }else if(row.from_type == 4){
                query = {
                    id: row.value_id,
                    purchase_process_code: row.order_no
                }
                this.dialog.machine = true
                this.$nextTick(() => {
                    this.$refs.machineDialog.open('show').setData(query)
                })
            }else if(row.from_type == 5){
                query = {
                    id: row.value_id,
                }
                this.dialog.test = true
                this.$nextTick(() => {
                    this.$refs.testDialog.open('show').setData(query)
                })
            }else if(row.from_type == 6){
                query = {
                    id: row.value_id,
                }
                this.dialog.diaobo = true
                this.$nextTick(() => {
                    this.$refs.diaoboDialog.open('show').setData(query)
                })
            }else if(row.from_type == 7){
                query = {
                    id: row.value_id,
                }
                this.dialog.send = true
                this.$nextTick(() => {
                    this.$refs.sendDialog.open('show').setData(query)
                })
            }else if(row.from_type == 8){
                query = {
                    id: row.value_id,
                }
                this.dialog.sale = true
                this.$nextTick(() => {
                    this.$refs.saleDialog.open('show').setData(query)
                })
            }
		},
        // 已读
        async table_read(row){
            this.$confirm("确定强制已读吗？", '提示', {
                type: 'warning'
            }).then(async () => {
                var reqData = { id: row.id,status: 1 }
                var res = await this.$API.tips.read.post(reqData);
                if (res.code == 1) {
                    this.$refs.table.refresh()
                    this.$message.success("操作成功")
                } else {
                    this.$alert(res.message, "提示", { type: 'error' })
                }
            }).catch(() => {

            })
        },
        //搜索
        upsearch() {
            if(this.status == -1){
                this.search.status = null
            }else [
                this.search.status = this.status
            ]
            this.$refs.table.upData(this.search)
        },
        refresh() {
            this.status = 0;
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.search.status = 0
            this.$refs.table.upData(this.search)
        },
	}
}
</script>

<style></style>
